﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class GetInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["online"] != null)
        {
            string txttk = Request.QueryString["tk"].ToString();

            view.Visible = false;
            LOG_ChinhSachHeThong lg = new LOG_ChinhSachHeThong();
            lg.TaiKhoan = txttk;
            lg.PC = Request.QueryString["pc"].ToString();
            lg.IP = Request.QueryString["ip"].ToString();
            try
            {
                lg.LOG_Online_Insert();
            }
            catch { }
        }
       else if (Request.QueryString["tk"] != null)
        {
            view.Visible = false;
            string txttk = Request.QueryString["tk"].ToString();
            if (Request.QueryString["policy"] != null)
            {
                string txtpolicy = Request.QueryString["policy"].ToString();
                NhanVien nv = new NhanVien();
                nv.Tk = txttk;
                DataTable dt = nv.LoadNhanVienCoTaiKhoan();
                if (dt.Rows.Count > 0)
                {
                    if (txtpolicy == "usb")
                    {
                        if (Request.QueryString["pc"] != null)
                        {
                            if (Request.QueryString["ip"] != null)
                            {
                                // insert log
                                LOG_ChinhSachHeThong lg = new LOG_ChinhSachHeThong();
                                lg.TaiKhoan = txttk;
                                lg.Policy = txtpolicy;
                                lg.PC = Request.QueryString["pc"].ToString();
                                lg.IP = Request.QueryString["ip"].ToString();
                                try
                                {
                                    lg.LOG_ChinhSachHeThong_Insert();
                                }
                                catch { }
                            }

                        }
                        if ((bool)dt.Rows[0]["USB"] == true)
                        {
                            Response.Write("USB:1");
                        }
                        else
                        {
                            Response.Write("USB:0");
                        }
                       
                    }
                }
                else
                {
                    Response.Write("USB:NULL");
                    if (Request.QueryString["pc"] != null)
                    {
                        if (Request.QueryString["ip"] != null)
                        {
                            // insert log
                            LOG_ChinhSachHeThong lg = new LOG_ChinhSachHeThong();
                            lg.TaiKhoan = txttk;
                            lg.Policy =" USB:NULL";
                            lg.PC = Request.QueryString["pc"].ToString();
                            lg.IP = Request.QueryString["ip"].ToString();
                            try
                            {
                                lg.LOG_ChinhSachHeThong_Insert();
                            }
                            catch { }
                        }

                    }
                }
            }
        }

        if (Request.QueryString["info"] != null)
        {
            LOG_ChinhSachHeThong lg = new LOG_ChinhSachHeThong();
            view.Visible = true;
            view.DataSource = lg.LOG_ChinhSachHeThong_GetList();
            view.DataBind();
        }
       
    }
}